home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13671 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: crchh327.rich.bnr.ca!jobell
  2. From: jobell@bnr.ca (Bret Bieghler)
  3. Newsgroups: comp.object,comp.lang.c++
  4. Subject: Defining Object Associations
  5. Date: 26 Mar 1996 18:58:04 GMT
  6. Organization: Nortel Technologies
  7. Message-ID: <4j9ens$jtq@crchh327.rich.bnr.ca>
  8. NNTP-Posting-Host: crchhd4a.rich.bnr.ca
  9.  
  10. Are there any preferences to defining object associations in
  11. C++.  My working system has several objects that must all
  12. communicate with each other, and many objects have to be in
  13. existence before creating another certain type.
  14.  
  15. For example, a LoggingManager object and DisplayManager object
  16. must be most constructed before creating a CommandDispatcher.
  17. Yet the CommandDispatcher also requires that an EventManager
  18. has been created, etc.
  19.  
  20. So I have code that goes along creating these objects, and
  21. when I create the CommandDispatcher I say,
  22.  
  23. CommandDispatcher* CD = new CommandDispatcher(LM, DM, EM);
  24.  
  25. etc.
  26.  
  27. But whenever the CommandDispatcher needs to talk a different
  28. type of object, I have to add it to the constructor and also
  29. ensure that the new object has all of its requirements
  30. fulfilled before created the CommandDispatcher.
  31.  
  32. This presents a headache because I have to worry about the
  33. order in which I create all of these things, and my code
  34. is rearranged a lot.
  35.  
  36. So what I would like is a global container of references to
  37. pointers that I can attach to each object as I declare its
  38. pointer (before I new it).  Then when I'm ready to new it
  39. I pass in all of the references (via a single struct or
  40. some sort) and everybody knows about everybody else.
  41.  
  42. So my question is, what is the preferred method of association?
  43. What is the best of way of letting an object know about another
  44. object?  Pointers that are declared in the constructor (requiring
  45. creation dependicies), or setDisplayManager(DM) type methods that
  46. allow you to set an object when you are reading (but since it
  47. is a "construction" I prefer it to be in the constructor).
  48.  
  49. Thanks for any suggestions you may have.
  50.  
  51. Regards,
  52.  
  53. Joseph A. Bell
  54. Nortel Technologies
  55.  
  56. -- 
  57. Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
  58. Northern Telecom / Bell-Northern Research
  59. "What?  Evacuate now, in our moment of triumph?  Surely you overestimate their chances."
  60.